﻿using XsqTech.SmartOA.EFCore;

namespace XsqTech.SmartOA.Respository
{
    public class BaseRespository<T> where T : class
    {
        MyDbContext _db;

        public BaseRespository(MyDbContext db)
        {
            _db = db;
        }

        public int Add(T m)
        {
            _db.Set<T>().Add(m);
            return _db.SaveChanges();
        }

        public IQueryable<T> Query()
        {
            return _db.Set<T>().AsQueryable();
        }

        public int Delete(object id)
        {
            _db.Remove(_db.Set<T>().Find(id));
            return _db.SaveChanges();
        }

        public int Update(T m)
        {
            _db.Set<T>().Update(m);
            return _db.SaveChanges();
        }
    }
}